<?php

class Quad_Form_Element_Option extends Quad_Html_Element {
	
	public $text;
	
	public function __construct($text, $value='') {
		parent::__construct('option');
		$this->text = $text;
		$this->setAttribute('value', $value);
	}
	
	public function __get($p) {
		if ($p == 'selected') {
			return (isset($this->_attributes['selected']) ? (bool) $this->_attributes['selected'] : false);
		}
		return parent::__get($p);
	}
	
	protected function _processAttributes(&$attr) {
		if (isset($attr['selected']) && $attr['selected']) {
			$attr['selected'] = 'selected';
		}
		else {
			unset($attr['selected']);
		}
		parent::_processAttributes($attr);
	}
	
	protected function _getInnerHTML() {
		return $this->text;
	}
	
	protected function _setInnerHTML($text) {
		$this->text = $text;
	}
	
	public function startOptgroup($label) {
		array_unshift($this->_decorations, 'StartOptgroup');
	}
	
	public function endOptgroup($label) {
		array_unshift($this->_decorations, 'EndOptgroup');
	}	
	
}